<?php

namespace app\common\behavior;


use fast\Http;
use think\exception\ValidateException;

class SmsBehavior
{

    protected $href = 'http://sms.jinpinyun.com:8888/index.php/api/sendsms';
    protected $options = [
        'userCode' => 'eric168',
        'userPwd' => '888888'
    ];
    /**
     * 短信发送行为
     * @param   $params
     * @return  boolean
     */
    public function smsSend(&$params)
    {

        $msgContent = "【短信通知】您的验证码是" . $params['code'] . ',请勿把验证码泄漏给他人';
        $options = [
            'mobile' => $params['mobile'],
            'msgContent' => $msgContent
        ];

        $options = array_merge($this->options, $options);
        $res = Http::post($this->href, $options);
        $res = json_decode($res, true);
        if (!isset($res['status']) || $res['status'] != 1) {
            throw new ValidateException('发送失败');
        }

        return true;
    }

    /**
     * 检测验证是否正确
     * @param   $params
     * @return  boolean
     */
    public function smsCheck(&$params)
    {
        return true;
    }


}
